home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / jcool01.zip / EX6_4.C < prev    next >
C/C++ Source or Header  |  1992-09-28  |  1KB  |  35 lines

  1. //
  2. // Copyright (C) 1991 Texas Instruments Incorporated.
  3. //
  4. // Permission is granted to any individual or institution to use, copy, modify,
  5. // and distribute this software, provided that this complete copyright and
  6. // permission notice is maintained, intact, in all copies and supporting
  7. // documentation.
  8. //
  9. // Texas Instruments Incorporated provides this software "as is" without
  10. // express or implied warranty.
  11. //
  12.  
  13. #include <cool/String.h>            // COOL String class
  14. #include <cool/Vector.h>            // COOL Vector class
  15.  
  16. #include <cool/Vector.C>
  17.  
  18. int my_sort (const CoolString& s1, const CoolString& s2) {
  19.   return ((s1 >= s2) ? -1 : 1);            // Reverse alphabetize
  20. }
  21.  
  22. int main (void) {
  23.   CoolVector<CoolString> v1(5);            // Declare CoolVector of CoolStrings
  24.   v1.push ("Texas");                // Add "Texas" 
  25.   v1.push ("Alaska");                // Add "Alaska" 
  26.   v1.push ("New York");                // Add "New York"
  27.   v1.push ("Alabama");                // Add "Alabama"
  28.   v1.push ("North Dakota");            // Add "North Dakota"
  29.   cout << v1 << "\n";                // Output the CoolVector
  30.   v1.sort (my_sort);                // Reverse sort the CoolVector
  31.   for (v1.reset(); v1.next(); )            // For each element 
  32.     cout << v1.value() << "\n";            // Output the value
  33.   return (0);                    // Exit with OK status
  34. }
  35.